﻿using System.Windows.Forms;

namespace GuidanceExplorerAddIn.Controls
{
    public static class TreeViewExtensions
    {
        public static TreeNode FindNodeByPath(this TreeView treeView,string fullPath)
        {
            foreach (TreeNode node in treeView.Nodes)
            {
                TreeNode foundNode = node.FindNodeByPath(fullPath);
                if (foundNode != null)
                {
                    return foundNode;
                }
            }
            return null;
        }
    }

    public static class TreeNodeExtensions
    {
        public static TreeNode FindNodeByPath(this TreeNode node, string fullPath)
        {
            if (node.FullPath.Equals(fullPath))
            {
                return node;
            }
            else if (fullPath.StartsWith(node.FullPath))
            {
                foreach (TreeNode child in node.Nodes)
                {
                    TreeNode foundNode = child.FindNodeByPath(fullPath);
                    if (foundNode != null)
                    {
                        return foundNode;
                    }
                }
            }
            return null;
        }
    }
}
